package com.cc.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(DiyProperties.class)
@ConditionalOnClass(DiyService.class)
@ConditionalOnProperty(prefix = "com.cc", value = "enabled", matchIfMissing = true)
public class ServiceAutoConfiguration {

    @Autowired
    private DiyProperties diyProperties;

    @Bean
    @ConditionalOnMissingBean()
    public DiyService diyService() {
        return new DiyService(diyProperties);
    }
}
